import time
from common_1.Ultils import ForumDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class ForumMyPosts:
    url = ""
    driver = ""
    def __init__(self):
        url = "http://127.0.0.1:9580/"
        self.driver = ForumDriver.driver
        self.driver.get(url)

    def ForumMyPostsTest(self):
        # 点击首页右上角
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown").click()
        # 弹窗
        WebDriverWait(self.driver,15).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown > div"))
        )
        # 点击“我的帖子”
        mypost_button = WebDriverWait(self.driver,15).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,"#index_user_profile"))
        )
        mypost_button.click()

        time.sleep(2)

        # 个人介绍板块
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.col-lg-4 > div > div > div > div")
        # 用户头像
        self.driver.find_element(By.CSS_SELECTOR,"#profile_avatar")
        # 用户昵称
        self.driver.find_element(By.CSS_SELECTOR,"#profile_nickname")
        # 发帖数
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(1)")
        # 邮箱信息
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(2)")
        # 注册日期
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(3)")
        # 用户发布的帖子列表
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.col")

        # 点击其中一条帖子
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong").click()

